package com.wind.plugin.configuration;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.util.xmlb.XmlSerializerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
 * @author wind
 * @version 1.0
 * @description: 持续化配置类
 * @date 2025/2/15 15:36
 */
@State(
        name = "WindPluginSettings",
        storages = @Storage("WindPluginSettings.xml")
)
public class PluginSettingsState implements PersistentStateComponent<PluginSettingsState> {

    public List<String> highlightClasses;
    public List<String> currencyFields;


    public PluginSettingsState() {
        this.highlightClasses = new ArrayList<>(Arrays.asList("java.lang.ThreadLocal"));
        this.currencyFields = new ArrayList<>(Arrays.asList("CUR", "curr", "currencyCode", "NBCBCURCODE", "CURRENCY_ID"));
    }


    public static PluginSettingsState getInstance() {
        return ApplicationManager.getApplication().getComponent(PluginSettingsState.class);
    }

    @Override
    public @Nullable PluginSettingsState getState() {
        return this;
    }

    @Override
    public void loadState(@NotNull PluginSettingsState state) {
        XmlSerializerUtil.copyBean(state, this);
    }

    public List<String> getHighlightClasses() {
        return this.highlightClasses;
    }

    public void setHighlightClasses(List<String> classes) {
        this.highlightClasses = classes;
    }

    public List<String> getCurrencyFields() {
        return currencyFields;
    }

    public void setCurrencyFields(List<String> fields) {
        this.currencyFields = fields;
    }
}
